Program Organization Units
In addition to the IEC standard, you can write you own code: sub-program or UDFB "User Defined Function Block" UDFB can be used as a sub-function block in another program of the application. It is described using FBD, LD, ST or IL language. Input / output parameters of a UDFB (as well as private variables) are declared in the variable editor as local variables of the UDFB.
Types | IEC 61131-3 | Written by end-user |
---|---|---|
Basic functions (has no memory) | Functions | Programs / Sub-programs |
Instantiated functions (keep track of the past) | Function Blocks (FB) | User-Defined Function Blocks (UDFB) |
Difference between Functions and Function Blocks
- Functions are expected to complete in one cycle
- Function Blocks can take several cycles to complete
Description of FB operation
Rather than halt the application, waiting for operations to complete, the FB typically gives control back to the application but does not set its Done output.
Examples of Operations Overrunning the Cycle Duration
- A motion command to move from one location to another can take several cycles to complete.
- Same for operations like reading/writing to files or reading and writing over TCP/IP can also take several cycles to complete.
Operation Sequence
- When a FB is called, it starts an operation and possibly does not complete it
- The FB is called in the next cycle, and it checks to determine if the operation is done
- If it is done, it sets the Done output. If not, it continues on
- Now the application knows that the operation is complete and can do what ever other processing it needs based on the FB being done